function dajSveMape()
{
	
	var req = createRequest(); // defined above
	//Create the callback:
	req.onreadystatechange = function() {
	if (req.readyState != 4) return; // Not there yet
	if (req.status != 200) {
	 // Handle request failure here...
	 return;
	}
	// Request successful, read the response
	var respXML= req.responseXML;
	var rID = respXML.getElementsByTagName("id");
	var rLAT = respXML.getElementsByTagName("lat");
	var rLGT = respXML.getElementsByTagName("lgt");
	var rZOOM = respXML.getElementsByTagName("zoom");
	// ... and use it as needed by your app.
	//alert(r2);
	for (var i=0;i<rID.length;i++)
		  {
		  var id=rID[i].childNodes[0].nodeValue;
		  var lat=rLAT[i].childNodes[0].nodeValue;
		  var lgt=rLGT[i].childNodes[0].nodeValue;
		  var zoom=rZOOM[i].childNodes[0].nodeValue;
		  dodajMarker(id,lat,lgt,zoom);
		  }
		  
	return;
	};
	req.open("GET","korisno/mape/get/", true);
	req.send();
}
function insertLinija(arg1,arg2,arg3,arg4,arg5,idlinije){
	
	//linije.push(arg1,arg2,arg3,arg4,arg5);
	//chek.push(chekiran);
	var fja="window.location='mapaStanice.html?idlinije="+idlinije+"';";
	$('#tblLinije').append("<tr>"
		+"<tr><td><name='"+arg1+"' value='"+arg1+"'>"+arg1+"</td>"
		+"<td>"+arg2+"</td>"
		+"<td>"+arg3+"</td>"
		+"<td>"+arg4+"</td>"
		+"<td>"+arg5+"</td>"
		+"<td><button type='button' onClick="+fja+">Stanice</button></td>");
	
}
function insertMapa(mark){
	var req = createRequest(); // defined above
	//Create the callback:
	req.onreadystatechange = function() {
	if (req.readyState != 4) return; // Not there yet
	if (req.status != 200) {
	 // Handle request failure here...
	 return;
	}
	// Request successful, read the response
	var resp= req.responseText;
	alert(resp);
	window.location.reload();
	// ... and use it as needed by your app.
	//alert(r2);
			  
	return;
	};
	
	parametri="?lat="+mark.getPosition().lat()+"&lgt="+mark.getPosition().lng()+"&zoom="+mark.zoom;
	req.open("GET","korisno/mape/insert"+parametri, true);
	req.send();
}
function updateMapa(mark){
	var req = createRequest(); // defined above
	//Create the callback:
	req.onreadystatechange = function() {
	if (req.readyState != 4) return; // Not there yet
	if (req.status != 200) {
	 // Handle request failure here...
	 return;
	}
	// Request successful, read the response
	var resp= req.responseText;
	alert(resp);
	// ... and use it as needed by your app.
	//alert(r2);
			  
	return;
	};
	
	parametri="?id="+mark.id+"&lat="+mark.getPosition().lat()+"&lgt="+mark.getPosition().lng()+"&zoom="+mark.zoom;
	req.open("GET","korisno/mape/update"+parametri, true);
	req.send();
}
function dodajMarker(id,lat,lgt,zoom) {
	  var image="slike/bus-ticket-icon.png";
	  var marker = new google.maps.Marker({
	    position: new google.maps.LatLng(lat,lgt),
	    map: map,
	    id: id,
	    icon: image,
	    draggable: true,
	    zoom: zoom
	  });
	  google.maps.event.addListener(marker,'rightclick',function() {
		  alert("delete()");
		  marker.setMap(null);
		  });
	  google.maps.event.addListener(marker, 'dragend', function() {
		  	updateMapa(marker);}
	  );
	  google.maps.event.addListener(marker, 'click', function() {
		    //map.setZoom(parseInt(marker.zoom));
		   href="linija.html?id="+marker.id;
		  $('#unosLinije').attr('href',href);
		  $('#linije').css( "visibility", "visible" );
		  $("#tblLinije").find("tr:gt(0)").remove();
		    Dekodiraj(marker);
		    dajLinije(marker.id);
		    map.setCenter(marker.getPosition());
		  });

	  markers.push(marker);
	}
function Dekodiraj(marker)
{
	geocoder.geocode({'latLng': marker.position}, function(results, status) {
	    if (status == google.maps.GeocoderStatus.OK) {
	      if (results[1]) {
	        
	        var city = "";
	        var state = "";
	        var r=results[1];
	        for(var i=0, len=r.address_components.length; i<len; i++) {
	        var ac = r.address_components[i];
	        if(ac.types.indexOf("locality") >= 0) city = ac.long_name;
	        if(ac.types.indexOf("administrative_area_level_1") >= 0) state = ac.long_name;
	        }
	        $('#pocetna').empty();
	        $('#pocetna').append(new String(city+" "+state));
	      } else {
	        alert('No results found');
	      }
	    } else {
	      alert('Geocoder failed due to: ' + status);
	    }
	  });
	}